package com.example.tally.frag_record;


import android.content.Intent;
import android.widget.Toast;
import com.example.tally.HistoryActivity;
import com.example.tally.MainActivity;
import com.example.tally.R;
import com.example.tally.db.DBManager;
import com.example.tally.db.TypeBean;

import java.util.List;

/**
 * 记录页面的支出模块
 */
public class OutcomeFragment extends BaseRecordFragment {

    @Override
    public void loadDataToGridView(){
        super.loadDataToGridView();
        List<TypeBean> outList = DBManager.getTypeList(0);
        typeBeanList.addAll(outList);
        typeBeanAdater.notifyDataSetChanged();
        if(!paramBean) {
            typeTv.setText("其他");
            typeIv.setImageResource(R.mipmap.ic_qita_fs);
        }
    }

    @Override
    public void saveAccountToDb() {
        accountBean.setKind(0);
        if(!paramBean) {
            DBManager.insertItemToAccounttb(accountBean);
        }else {
            DBManager.updateItemToAccounttb(accountBean);
        }
        Toast.makeText(getContext() , "保存成功" , Toast.LENGTH_SHORT).show();
        Intent intent = new Intent();
        if("histroy".equals(this.getDirection())) {
            intent.setClass(this.getActivity(), HistoryActivity.class);
        }else {
            intent.setClass(this.getActivity(), MainActivity.class);
        }
        this.getActivity().finish();
    }

}